﻿Imports ATS.Business.Entities
Imports ATS.UI.Process

Public Class frmLogin

    Private _authResult As AuthenticationResult = Nothing
    Private _upc As SubmitterUserProcess = Nothing
    Dim key As String = "ATSbyJOKOforGENCPROSv2.1"

    Public Sub New()
        InitializeComponent()

        _upc = New SubmitterUserProcess()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        Application.Current.Shutdown()
    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        If EntryValidation.ValidatePassword(txtPassword) And EntryValidation.ValidateText(txtUserName, False) Then
            Dim tripleDES As New tripleDes
            tripleDES.secretKey = key
            tripleDES.data = txtPassword.Password
            tripleDES.encryptdata()
            Select Case _upc.AuthenticateUser(txtUserName.Text, tripleDES.encryptedData)
                Case AuthenticationResult.Authorised
                    DialogResult = True
                    Main.v_username = txtUserName.Text
                    Me.Close()
                Case AuthenticationResult.AccountDoesNotExist
                    MessageBox.Show("Username does not exist.", "Error", MessageBoxButton.OK)
                Case AuthenticationResult.AccountLocked
                    MessageBox.Show("Your account has been locked. Contact your administrator for assistance or wait 30 minutes to log on again.", "Account Locked", MessageBoxButton.OK, MessageBoxImage.Warning)
                Case AuthenticationResult.InvalidUsernameOrPassword
                    MessageBox.Show("Note: Passwords are case sensitive.", "Wrong User Id or Password", MessageBoxButton.OK, MessageBoxImage.Warning)
            End Select
        End If
    End Sub



    Private Sub txtPassword_PasswordChanged(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles txtPassword.PasswordChanged
        EntryValidation.ValidatePassword(txtPassword)
    End Sub

    Private Sub txtUserName_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles txtUserName.TextChanged
        EntryValidation.ValidateText(txtUserName, False)
    End Sub



End Class

